import { checkMaxDivideWtihNumber, BoolStrWithBoolen } from './common'
/**
 * 学龄前期
 */
export function lessThanAcuteControlLevels(attrs, age) {
  const { attr154, attr149, attr238, attr143, attr237, attr191, attr192 } =
    attrs
  const tmp = {}
  if (attr154) {
    attr154 === '有' ? (tmp['attr1'] = '1') : (tmp['attr1'] = '0')
  } else {
    tmp['attr1'] = null
  }

  if (attr149) {
    const tmpNumber = checkMaxDivideWtihNumber(attr149, null, true)
    if (!isNaN(tmpNumber) && tmpNumber !== -1) {
      tmpNumber >= 92 ? (tmp['attr2'] = '0') : (tmp['attr2'] = '1')
    }
    // 小于6岁不需要改
    // const tmpNumber = checkMaxDivideWtihNumber(attr149, null, true)
    // if (tmpNumber > 90 && tmpNumber < 95) {
    //   tmp['attr2'] = 0
    // } else if (tmpNumber !== -1 && tmpNumber === 90) {
    //   tmp['attr2'] = 1
    // } else if (tmpNumber !== -1 && tmpNumber < 90) {
    //   tmp['attr2'] = 2
    // } else {
    //   tmp['attr2'] = null
    // }
  } else {
    tmp['attr2'] = null
  }

  if (attr238) {
    if (attr238.includes('能成句')) tmp['attr3'] = 0
    if (attr238.includes('说单字')) tmp['attr3'] = 1
  } else {
    tmp['attr3'] = null
  }
  console.log('attr143 =' + attr143)
  if (attr143) {
    const tmpNumber = checkMaxDivideWtihNumber(attr143, null, true)
    console.log('tmpNumber =' + tmpNumber)
    tmp['attr4'] = null
    if (!isNaN(tmpNumber)) {
      if (
        (age >= 4 && age <= 5 && tmpNumber <= 180) ||
        (age >= 0 && age <= 3 && tmpNumber <= 200)
      ) {
        tmp['attr4'] = '0'
      } else if (
        (age >= 4 && age <= 5 && tmpNumber > 180) ||
        (age >= 0 && age <= 3 && tmpNumber > 200)
      ) {
        tmp['attr4'] = '1'
      }
    }
  } else {
    tmp['attr4'] = null
  }

  if (attr237) {
    attr237 === '有' ? (tmp['attr5'] = '1') : (tmp['attr5'] = '0')
  } else {
    tmp['attr5'] = null
  }

  const b1 = attr191 === '闻' ? true : false
  const b2 = attr192 && attr192.includes('较弱乃至消失') ? true : false
  if (b2) {
    tmp['attr6'] = 1
  } else if (b1) {
    tmp['attr6'] = 0
  } else {
    tmp['attr6'] = null
  }
  return tmp
}

/**
 * 学龄
 * @param {*} attrs
 */
export function greaterEqualAcuteControlLevels(attrs) {
  const {
    attr161,
    attr162,
    attr238,
    attr155,
    attr156,
    attr159,
    attr160,
    attr191,
    attr192,
    attr194,
    attr225,
    attr226,
    attr149,
  } = attrs
  const tmp = {}

  if (attr161 && attr161.includes('走路时')) {
    tmp['attr1'] = 0
  } else if (attr161 && attr161.includes('说话时')) {
    tmp['attr1'] = 1
  } else if (attr161 && attr161.includes('休息时')) {
    tmp['attr1'] = 2
  } else {
    tmp['attr1'] = null
  }

  if (attr162 && attr162.includes('可平卧')) {
    tmp['attr2'] = 0
  } else if (attr162 && attr162.includes('喜坐位')) {
    tmp['attr2'] = 1
  } else if (attr162 && attr162.includes('前弓位')) {
    tmp['attr2'] = 2
  } else {
    tmp['attr2'] = null
  }

  if (attr238 && attr238.includes('能成句')) {
    tmp['attr3'] = 0
  } else if (attr238 && attr238.includes('成短句')) {
    tmp['attr3'] = 1
  } else if (attr238 && attr238.includes('说单字')) {
    tmp['attr3'] = 2
  } else if (attr238 && attr238.includes('难以说话')) {
    tmp['attr3'] = 3
  } else {
    tmp['attr3'] = null
  }
  // 精神意识
  // 多选不给自动选择
  if (
    attr155 &&
    attr155.includes('焦虑') &&
    !attr155.includes('嗜睡') &&
    !attr155.includes('意识不清')
  ) {
    if (!attr156) {
      tmp['attr4'] = null
    } else if (attr156.includes('可有，')) {
      tmp['attr4'] = 0
    } else if (attr156.includes('长时间，')) {
      tmp['attr4'] = 1
    } else if (attr156.includes('经常')) {
      tmp['attr4'] = 2
    }
  } else if (
    ((attr155 && attr155.includes('嗜睡')) ||
      (attr155 && attr155.includes('意识不清'))) &&
    (!attr156 || attr156.length <= 0)
  ) {
    tmp['attr4'] = 3
  } else {
    tmp['attr4'] = null
  }

  if (attr159 === '有' && attr160) {
    if (attr160.includes('可有')) {
      tmp['attr5'] = 1
    } else if (attr160.includes('通常有')) {
      tmp['attr5'] = 2
    } else if (attr160.includes('胸腔反常运动')) {
      tmp['attr5'] = 3
    }
  } else if (attr159 === '无') {
    tmp['attr5'] = 0
  } else {
    tmp['attr5'] = null
  }

  // 如果用户多选了就不自动选择了。
  console.log('attr191 =' + attr191)
  console.log('attr192 =' + attr192)
  console.log('attr192.length =' + attr192.length)
  console.log('attr192 =' + Array.isArray(attr192))
  if (attr191 === '闻' && attr192.includes('散在') && attr192.length === 1) {
    tmp['attr6'] = 0
  } else if (
    attr191 === '闻' &&
    attr192.includes('弥漫') &&
    attr192.length === 1
  ) {
    tmp['attr6'] = 1
  } else if (
    attr191 === '闻' &&
    attr192.includes('吸气相') &&
    attr192.includes('呼气相') &&
    attr192.length === 2
  ) {
    tmp['attr6'] = 2
  } else if (
    attr191 === '闻' &&
    attr192.includes('较弱乃至消失') &&
    attr192.length === 1
  ) {
    tmp['attr6'] = 3
  } else {
    tmp['attr6'] = null
  }

  if (attr194) {
    if (attr194.includes('略增加')) {
      tmp['attr7'] = 0
    } else if (attr194.includes('增加') && !attr194.includes('明显增加')) {
      tmp['attr7'] = 1
    } else if (attr194.includes('明显增加')) {
      tmp['attr7'] = 2
    } else if (attr194.includes('减慢或不规则')) {
      tmp['attr7'] = 3
    }
  } else {
    tmp['attr7'] = null
  }

  const a1 = checkMaxDivideWtihNumber(attr225, null, true)
  const a2 = checkMaxDivideWtihNumber(attr226, null, true)
  if (a2 > 80) {
    tmp['attr8'] = 0
  } else if (a1 > 80 && a2 > 50 && a2 < 80) {
    tmp['attr8'] = 1
  } else if (a1 <= 50 && a2 <= 60 && a1 !== -1 && a2 !== -1) {
    tmp['attr8'] = 2
  }

  const c1 = checkMaxDivideWtihNumber(attr149, null, true)
  if (c1 > 90 && c1 < 95) {
    tmp['attr9'] = 0
  } else if (c1 !== -1 && c1 === 90) {
    tmp['attr9'] = 1
  } else if (c1 !== -1 && c1 < 90) {
    tmp['attr9'] = 2
  } else {
    tmp['attr9'] = null
  }
  return tmp
}
